//
//  DiscountCell.m
//  meituan
//
//  Created by jinzelu on 15/7/2.
//  Copyright (c) 2015年 jinzelu. All rights reserved.
//

#import "DiscountCellH.h"

@interface DiscountCellH ()
{
    UIView *_backView1;
}

@end

@implementation DiscountCellH

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _backView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH,87)];
        [self.contentView addSubview:_backView1];
        NSArray *titleArray = [NSArray arrayWithObjects:@"发起检测",@"参与众测",@"最新报告",@"查一查",nil];
        NSArray *imageArray = [NSArray arrayWithObjects:@"main_one",@"main_two",@"main_three",@"main_free",nil];
        
        CGFloat buttonW ;
        CGFloat buttonH ;
        CGFloat headermarge;
        if (IS_IPHONE_5 ||IS_IPHONE_4_OR_LESS) {
            headermarge = 25;
            buttonW = 42;
            buttonH = 60;
        }else{
            headermarge = 25;
            buttonW = 47;
            buttonH = 64;
        }
        CGFloat margeH = (87-buttonH-15)/2;
        CGFloat marge = (SCREEN_WIDTH-(4*buttonW)-(headermarge*2))/3;
        
        for (int i = 0; i <titleArray.count; i++) {
            NSInteger index = i % 4;
            NSInteger page = i / 4;
            // 圆角按钮
            CGRect frame = CGRectMake(index * (buttonW+marge)+headermarge,(page  * (buttonH+margeH))+margeH, buttonW, buttonH);
            NSString *title = titleArray[i];
            NSString *imageStr =[NSString stringWithFormat:@"%@",imageArray[i]];
            
            JZMTBtnView *btnView = [[JZMTBtnView alloc] initWithFrame:frame];
//            btnView.backgroundColor = [UIColor redColor];
            btnView.imageStr = imageStr;
            btnView.titleStr = title;
            btnView.titleColor = [UIColor colorWithHexString:@"525252"];
            btnView.font = [UIFont systemFontOfSize:13];
            btnView.tag = i;
            [_backView1 addSubview:btnView];
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(OnTapBackView:)];
            [btnView addGestureRecognizer:tap];
        }
    }
        return self;
}

-(void)OnTapBackView:(UITapGestureRecognizer *)sender{

    NSInteger index = sender.view.tag;
    
    if ([_delegate respondsToSelector:@selector(didSelectDiscountIndex:)]) {
        [_delegate didSelectDiscountIndex:index];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}


- (void)awakeFromNib {
    // Initialization code
}
@end
